<?php
/**
 * Created by PhpStorm.
 * User: Jason
 * Date: 2017/7/28
 * Time: 0:13
 */

namespace Admin\Service;


class UserService
{
    public function getUserInfoByIds($Ids)
    {
        $map = array('id' => array('in', $Ids));

        $Model = M('User');
        $userList = $Model->field('id, nickname, avatar_url')->where($map)->select();
        $userMap = array();
        foreach ($userList as $key=> $val) {
            $userMap[$val['id']] = $val;
        }
        return $userMap;
    }

    /**
     * 获取马甲号信息
     */
    public function getAliasUserInfo()
    {
        $model = M('User');
        $map = array(
            'is_alias' => 1,
            'is_delete' => 0
        );
        $aliasInfo = $model->where($map)->field('id, nickname, avatar_url')->select();
        return $aliasInfo;
    }

    /**
     * 新增马甲号
     */
    public function addAlias()
    {
        $param = I('post.');
        $model = M('User');
        $param['is_alias'] = 1;
        $imgList = M('Image')->where(array('img_type'=>30))->field('url')->select();
        $urlList = array_column($imgList, 'url');
        $imgKey = array_rand($urlList);
        $param['avatar_url'] = $urlList[$imgKey];
        $userId = $model->add($param);
        return $userId;
    }
}